package com.xubao.ali.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xubao.ali.entity.Books;
import com.xubao.ali.services.BooksService;

/**
 * Servlet implementation class BooksUpdateController
 */
public class BooksUpdateController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bookid = request.getParameter("bookid");
		String typeid = request.getParameter("typeid");
		String bookname = request.getParameter("bookname");
		String authorname = request.getParameter("authorname");
		String bookcover = request.getParameter("bookcover");
		String bookintroduction = request.getParameter("bookintroduction");
		String popularity = request.getParameter("popularity");
		String latestchapter = request.getParameter("latestchapter");
		String updatetime = request.getParameter("updatetime");
		String readingprogress = request.getParameter("readingprogress");
		String totalword = request.getParameter("totalword");
		String state_id = request.getParameter("serialization_or_end");
		
		
		Books book = new Books();
		book.setBook_id(Integer.parseInt(bookid));
		book.setType_id(Integer.parseInt(typeid));
		book.setBook_name(bookname);
		book.setAuthor_name(authorname);
		book.setBook_cover(bookcover);
		book.setBook_introduction(bookintroduction);
		book.setPopularity(Integer.parseInt(popularity));
		book.setLatest_chapter(latestchapter);
		try {
			book.setUpdate_time(new SimpleDateFormat("yyyy-MM-dd").parse(updatetime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		book.setReading_progress(Integer.parseInt(readingprogress));
		book.setTotal_word(Integer.parseInt(totalword));
		book.setState_id(Integer.parseInt(state_id));
		
		BooksService bs = new BooksService();
		bs.update(book);
		
		request.getRequestDispatcher("init_type").forward(request, response);
	}

}
